import { BaseDrawInfo, BaseLineInfo } from "..";
import { drawerAop } from "../drawer-aop";

export interface LineInfo {
  x1: number;
  y1: number;
  x2: number;
  y2: number;
}

export interface LineDrawInfo extends BaseDrawInfo, LineInfo, BaseLineInfo {}

export class LineHelper {
  static _helper: LineHelper = new LineHelper();

  static getInstance() {
    return this._helper;
  }

  protected constructor() {}

  @drawerAop({ keepCtx: true })
  draw(ctx: CanvasRenderingContext2D, drawInfo: LineDrawInfo) {
    const { x1, y1, x2, y2 } = drawInfo;
    ctx.moveTo(x1, y1);
    ctx.lineTo(x2, y2);
    ctx.stroke();
  }
}

export const line = LineHelper.getInstance();
